<?php
if (!session_start()) session_start();
if (!isset($_SESSION['kiemtradangnhapthinguyet']) || $_SESSION['kiemtradangnhapthinguyet'] != 1) {
    header('location: ../../../index.php');
    die();
}
$pageSize = 8;
$pageNum  = 1;
if (isset($_GET['pageNum']) == true) $pageNum = $_GET['pageNum'];
$totalRows = 0;
$tukhoa    = '';
if (isset($_GET['tukhoa'])) $tukhoa = $_GET['tukhoa'];
if (isset($_GET['idmenu'])) $idmenu = $_GET['idmenu'];
$table = "menu_domain";
$res   = $qt->get_phantrang_db($pageNum, $pageSize, $totalRows, $table, -1, -1, " and ten_vi like '%$tukhoa%'");


?>
<script>
    $(document).ready(function () {
        $("img.anhien").click(function () {
            id = $(this).attr("idanhien");
            obj = this;
            $.ajax({
                url:'anhien.php',
                data:"table=<?=$table?>&loai=anhien&id=" + id,
                cache:false,
                success:function (data) {
                    //alert(data);
                    obj.src = 'imgs/anhien_' + data + '.jpg';
                    if (data == "1.jpg") obj.title = "Nhắp vào để ẩn";
                    else obj.title = "Nhắp vào để hiện";
                }
            });
        });
        $("#chonhet").click(function () {
            var status = this.checked;
            $("input[name='chon']").each(function () {
                this.checked = status;
            })
        });

        $('#capnhatthutu').click(function () {
            var listid = "";
            $("input[name='listid']").each(function () {
                listid = listid + "," + this.value;
            });
            var listtt = "";
            $("input[name='thutu']").each(function () {
                listtt = listtt + "," + this.value;
            });
            listid = listid.substr(1);
            listtt = listtt.substr(1);
            if (listid == "") {
                alert("Bạn chưa chọn tin nào");
                return;
            }
            document.location = "capnhatthutu.php?table=<?=$table?>&listid=" + listid + "&listtt=" + listtt;
        });

        $("#xoahet").click(function () {
            var listid = "";
            $("input[name='chon']").each(function () {
                if (this.checked) listid = listid + "," + this.value;
            })
            listid = listid.substr(1);
            if (listid == "") {
                alert("You have not selected !");
                return;
            }
            hoi = confirm("Delete all ?");
            if (hoi == true)
                document.location = "do_delete_list_record.php?table=<?php echo $table; ?>&p=<?php echo $table; ?>_quanly&listid=" + listid;
        });
    });
</script>
<div class="dangnhap_title">
    <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
    <span style="font-size:9px;">>></span> Menu domain
</div>
<div style="float:right; width:710px; text-align:right;">
    <form method="get" action="">

        <b>Key words:</b> <input type="tukhoa" name="tukhoa"/>
        <input name="p" type="hidden" value="<?php echo $table; ?>_quanly"/>
        <input type="submit" value="Search">
    </form>
</div>

<div style="float:right; width:710px; position: relative;">
    <input title="Chọn rồi bấm xóa" type="button" name="xoahet" id="xoahet" value=" Xoá nhiều " class="nut"
           style="float:left; margin-top:24px;"/>
    <input title="Cập nhật thứ tự" type="button" name="capnhatthutu" id="capnhatthutu" value=" Cập nhật thứ tự "
           class="nut" style="float:left; margin-top:24px;"/>

    <div class="phan_trang">
        <?php echo $qt->pagesList($totalRows, $pageNum, $pageSize); ?>
    </div>
    <img src="imgs/them.png" onclick="create_record('<?php echo $table; ?>_them');" width="48" height="48" border="0"
         style="cursor: pointer; float:right;"/>
</div>
<table border="0" cellpadding="0" cellspacing="0" style="float:right; width:710px; text-align:left;">
    <tr>
        <td width="40" class="td_style1"><input type="checkbox" name="chonhet" id="chonhet"/></td>
        <td width="50" class="td_style1"><b>Số</b></td>
        <td class="td_style1"><b>Tên</b></td>
        <td width="20" class="td_style1" style="padding-right:10px;"><b>Ẩn hiện</b></td>
        <td width="51" class="td_style1"><b>Thứ tự</b></td>
        <td width="80" class="td_style1" align="center"><b>Công cụ</b></td>
    </tr>
    <? $dem = 0; while ($row = mysql_fetch_assoc($res)) {
    $dem++ ?>
    <tr>
        <td class="td_style2"><input type="checkbox" name="chon" id="chon" value="<?php echo $row['id']; ?>"
                                     class="chon"/></td>
        <td class="td_style2"><?php echo $dem; ?></td>
        <td class="td_style2">
            <b><?php echo $row['ten_vi']; ?></b></td>
        <td class="td_style2" align="center" style="padding-right:10px;">
            <img alt="" idanhien="<?=$row['id']?>" src="imgs/anhien_<?=$row['anhien']?>.jpg" border="0"
                 style="cursor: pointer;" class="anhien"/>
        </td>
        <td class="td_style2" align="center"><input name="thutu" type="text" value="<?=$row['thutu']?>"
                                                    style="width:30px;text-align:center;"/>

            <input name="listid" type="hidden" value="<?=$row['id']?>"/>
        </td>
        <td class="td_style2" align="center">
            <img src="imgs/pencil.png" onclick="update_record('<?php echo $table; ?>_sua','<?php echo $row['id']; ?>');"
                 width="16" height="16" border="0" style="cursor: pointer;"/>
            &nbsp;&nbsp;
            <img src="imgs/xoa.png"
                 onclick="if (confirm('Are you sure ?')) do_delete_record('<?php echo $table; ?>','<?php echo $row['id']; ?>');"
                 width="16" height="16" border="0" style="cursor: pointer;"/></td>
    </tr>
    <?php
}
    ?>
</table>
